// 回合结算模块
class lucky extends eui.Component{
    private contentBg:egret.Sprite = new egret.Sprite();
    private uiBg:eui.Image;
    private endTx:eui.Label;
    public constructor(){
        super();
        this.once(eui.UIEvent.COMPLETE,this.onComplete,this);
        this.skinName = "src/Game/gameRoom/end/luckySkin.exml";
    }
    private onComplete(){
        this.addChild(this.contentBg);
    }   
    public setContent(msg:any,zhaMaConut:number){
        for(var i=this.contentBg.numChildren;i>0;i--){
            this.contentBg.removeChildAt(i-1);
        }
        let count:number = Math.min(zhaMaConut,msg.length);
        //alert(count+":("+zhaMaConut+","+msg.length+")");
        if(count <= 0) return;
        console.log('luckyResult', msg, count);
        const paiCount = msg.reduce((paiNumbers, card) => {
            if (!card.card.suitType) {
                return paiNumbers 
            } else {
                return paiNumbers + 1
            }
        }, 0)
        console.log('paiCount', paiCount);
        msg.forEach((luckyData, i) => {
            if (!luckyData.card.suitType) {
                luckyData.points.forEach((point, pIndex) => {
                    const luckyYao = new Yaoshaizidange()
                    if (paiCount === 0) {
                        luckyYao.x = 90*i + pIndex * 32 + 55;//15+(32*((i+1)%5));
                    } else {
                        luckyYao.x = 90*i + pIndex * 32 - 50;//15+(32*((i+1)%5));
                    }
                    luckyYao.y = 35;//8+(Math.floor((i+1)/5)*(45)); 
                    this.contentBg.addChild(luckyYao)
                    console.log('luckyYao', luckyYao);
                    luckyYao.playNoAction(point)
                })
                // const luckyYao = new Yaoshaizidange()
                // luckyYao.x = 32*i;//15+(32*((i+1)%5));
                // luckyYao.y = 35;//8+(Math.floor((i+1)/5)*(45)); 
                // this.contentBg.addChild(luckyYao)
                // console.log('luckyYao', luckyYao);
                // luckyYao.playAction(luckyData.card.count)
                return 
            }
            var pokerMc = new handPoker();            
            pokerMc.setContent(luckyData.card.suitType+"_"+luckyData.card.count+"_png");
            pokerMc.scaleX = pokerMc.scaleY = 0.38;
            this.contentBg.addChild(pokerMc);
            pokerMc.x = 32*i;//15+(32*((i+1)%5));
            pokerMc.y = 35;//8+(Math.floor((i+1)/5)*(45)); 
            this.uiBg.width = 32*(i+1);  
            this.width = this.uiBg.width;
            this.endTx.x = (this.uiBg.width - 40)/2;               
            if(luckyData.win == true){
                pokerMc.alpha = 1;
                let gou:egret.Bitmap = MyLibrary.createBitmapByName("endGou_png",true);
                gou.x = pokerMc.x+20;//+ (pokerMc.width/2);
                gou.y = pokerMc.y + 50;
                this.addChild(gou);
            }else{
                // pokerMc.alpha = 0.6;
            }
        })
        // for(var i=0;i<count+1;i++){
        //     if(i<count){
        //         if (!msg[i].card.suitType) {
        //             const luckyYao = new Yaoshaizidange()
        //             luckyYao.x = 32*i;//15+(32*((i+1)%5));
        //             luckyYao.y = 35;//8+(Math.floor((i+1)/5)*(45)); 
        //             this.contentBg.addChild(luckyYao)
        //             console.log('luckyYao', luckyYao);
        //             luckyYao.playAction(msg[i].card.count)
        //             return 
        //         }
        //         var pokerMc = new handPoker();            
        //         pokerMc.setContent(msg[i].card.suitType+"_"+msg[i].card.count+"_png");
        //         pokerMc.scaleX = pokerMc.scaleY = 0.38;
        //         this.contentBg.addChild(pokerMc);
        //         pokerMc.x = 32*i;//15+(32*((i+1)%5));
        //         pokerMc.y = 35;//8+(Math.floor((i+1)/5)*(45)); 
        //         this.uiBg.width = 32*(i+1);  
        //         this.width = this.uiBg.width;
        //         this.endTx.x = (this.uiBg.width - 40)/2;               
        //         if(msg[i].win == true){
        //             pokerMc.alpha = 1;
        //             let gou:egret.Bitmap = MyLibrary.createBitmapByName("endGou_png",true);
        //             gou.x = pokerMc.x+20;//+ (pokerMc.width/2);
        //             gou.y = pokerMc.y + 50;
        //             this.addChild(gou);
        //         }else{
        //             pokerMc.alpha = 0.6;
        //         }
        //     }  
        // }   
    }
}